<template>
  <div class="message">
    <el-tabs type="border-card">
      <el-tab-pane label="我的信息">
        <el-form ref="form" :model="form" label-width="80px">
          <div class="top">
            <el-form-item label="*用户账号">
              <el-input v-model="form.username" readonly=""></el-input>
            </el-form-item>
            <el-form-item label="*用户名称">
              <el-input v-model="form.nickname" readonly=""></el-input>
            </el-form-item>
            <el-form-item label="*姓别">
              <el-input v-model="form.sex" disabled></el-input>
            </el-form-item>
            <el-form-item label="*类型">
              <el-input v-model="form.type" disabled></el-input>
            </el-form-item>
            <el-form-item label="联系电话">
              <el-input v-model="form.phone" readonly=""></el-input>
            </el-form-item>
            <el-form-item label="邮箱">
              <el-input v-model="form.email" readonly=""></el-input>
            </el-form-item>
            <el-form-item label="生效时间:">
              <el-col :span="11">
                <el-date-picker
                  type="date"
                  placeholder="选择日期"
                  v-model="form.createtime"
                  style="width: 100%"
                  disabled
                ></el-date-picker>
              </el-col>
            </el-form-item>
            <el-form-item label="详细住址:">
              <el-input v-model="form.homeaddress" disabled></el-input>
            </el-form-item>
            <el-form-item label="我的车位:">
              <el-input v-model="form.parkname" readonly=""></el-input>
            </el-form-item>
            <el-form-item label="计费状态:">
              <el-input v-model="form.coststatus" readonly=""></el-input>
            </el-form-item>
          </div>
          <div class="bottom">
            <el-form-item label="我的描述">
              <el-input
                type="textarea"
                v-model="form.note"
                readonly=""
              ></el-input>
            </el-form-item>
          </div>
        </el-form>
      </el-tab-pane>
    </el-tabs>
    <h2>头像信息/更换</h2>
    <div class="userimg">
      <!-- <div>
        <el-upload
          class="avatar-uploader"
          action="https://jsonplaceholder.typicode.com/posts/"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
          disabled
        >
          <img v-if="imageLocal" :src="imageLocal" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
        <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="imageLocal" alt="" />
        </el-dialog>
      </div> -->
      <!-- 预览 -->
      <div class="demo-image__preview">
        <el-image
          style="width: 300px; height: 300px"
          :src="imageU"
          :preview-src-list="srcList"
        >
        </el-image>
      </div>

      <div>
        <el-upload
          class="avatar-uploader"
          :action="url"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
        >
          <img v-if="imageUrl" :src="imageUrl" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      srcList: [
         
        ],
imageU:'',
      dialogVisible: false,
      //图片地址
      imageUrl: "",
      imageLocal: "",
      url: "",
      token: null,
      //表单文件
      form: {},
    };
  },
  methods: {
    //上传头像
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    //初始化
    getFormData() {
      this.$axios
        .post("users/getMyId", {
          id: "",
          token: sessionStorage.getItem("token"),
        })
        .then((res) => {
          this.form = res.data[0];
          this.imageLocal =
            "http://community.byesame.com/file/" + this.form.icon;
             this.imageU= this.imageLocal
              this.srcList.push(this.imageLocal)
          this.token = sessionStorage.getItem("token");
          this.url =
            "http://community.byesame.com/users/updateIcon" +
            "?" +
            "token=" +
            this.token;
        });
    },
  },
  created() {
    this.getFormData();
  },
};
</script>

<style lang="scss" scoped>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.message::v-deep {
  .userimg {
    display: flex;
    flex-direction: row;
  }
  .top {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    flex-wrap: wrap;
    .el-form-item {
      width: 48%;
    }
  }
  .bottom {
    display: flex;
    justify-content: center;
    .el-form-item {
      width: 98%;
    }
  }
}
</style>